package com.triptogether.utils.androidsystem;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;

import com.triptogether.utils.log.Logger;

public class SystemUtils {
	
	private static final String TAG = Logger.makeLogTag(SystemUtils.class);

	/**
	 * @return Application's version code from the {@code PackageManager}.
	 */
	public static int getAppVersion(Context context) {
		try {
			PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(),
			                                                                     0);
			return packageInfo.versionCode;
		} catch (NameNotFoundException e) {
			Logger.LOGE(TAG, e.getMessage(), e);
			// should never happen
			throw new RuntimeException("Could not get package name: " + e);
		}
	}
}
